﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AMail.Modules.Messages.Models;
using AMail.Common.Interfaces.Data;
using System.ComponentModel;
using Elentok.Common.Wpf.Controls;

namespace AMail.Modules.Messages.Views
{
  /// <summary>
  /// Interaction logic for MessageListView.xaml
  /// </summary>
  public partial class MessageListView : UserControl
  {
    private ListViewDragDropManager<IMailMessage> dragDropManager;

    public MessageListView(IMessageListViewModel viewModel)
    {
      InitializeComponent();

      this.DataContext = viewModel;
      this.dragDropManager = new ListViewDragDropManager<IMailMessage>(this.listView);

      this.InputBindings.Add(
        new InputBinding(viewModel.DeleteMessagesCommand, new KeyGesture(Key.Delete)));

      this.InputBindings.Add(
        new InputBinding(viewModel.ViewSourceCommand, new KeyGesture(Key.F3)));

      this.InputBindings.Add(
        new InputBinding(
          viewModel.ImportFromClipboardCommand, 
          new KeyGesture(Key.V, ModifierKeys.Control)));
    }

    private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      var messages = this.listView.SelectedItems.Cast<IMailMessage>().ToList();
      (this.DataContext as IMessageListViewModel).SelectedMessagesChangedCommand.Execute(messages.AsReadOnly());
    }
  }
}
